// 账号列表
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";

//查询矩阵账号【分页查询】
export async function accountQuery (data) {
  const res = await request.post('/business/matrix/account/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


//查询矩阵账号【非分页查询】
export async function accountQuery2 (data) {
  const res = await request.post('/business/matrix/account/pageList', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//删除矩阵账号
export async function delAccount (data) {
  const res = await request.post('/business/matrix/account/delete', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//修改矩阵账号
export async function updateAccount (data) {
  const res = await request.post('/business/matrix/account/update', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （cookie发布）
export async function accountCookie(username,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:2,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/cookie${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （h5发布）
export async function accountH5(username,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:1,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/h5${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 获取D音开放平台授权登陆二维码 （用户库使用）
export async function accountUser(merchantId,types) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    merchantId: merchantId,  // 商户id,
    types:types
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/userLibrary${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （代员工发布）
export async function accountCode(username,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:3,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/code${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 获取K手开放平台授权二维码 (无痕授权也是调用这个)
export async function kuaishouCode(username,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/kuaishou/open/auth/code${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}



// 获取K手开放平台授权二维码 (无痕授权也是调用这个)（包含分组）
export async function ksGroupCode(username,id,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    groupId:id,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/kuaishou/open/auth/code${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （cookie发布包含分组）
export async function accountGroupCookie(username,item,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:2,
    groupId:item.id,
    groupName:item.groupName,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/cookie${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （h5发布包含分组）
export async function accountGroupH5(username,item,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:1,
    groupId:item.id,
    groupName:item.groupName,
    merchantId:merchantId
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/h5${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 1.抖音h5 2.抖音无痕(cookid) 3.抖音代员工 4.快手
// 获取D音开放平台授权登陆二维码 （代员工发布包含分组）
export async function accountGroupCode(username,item,merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username: username,
    types:3,
    groupId:item.id,
    groupName:item.groupName,
    merchantId: merchantId  // 商家id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/open/auth/code${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}



// 校验D音自研接口授权是否过期——该接口不需要使用
export async function douyinCheck (data) {
  const res = await request.post('/business/matrix/account/douyin/check', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 校验D音自研接口授权是否过期(暂未使用）
export async function douyinCheck2(id) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    id: id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/check${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 获取D音自研接口授权二维码
export async function douyinCodes(area, username) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    area: area,
    username: username
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/account/douyin/scan_code${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// D音开放平台回调【前端无需对接】
export async function accountOpenAuthCB() {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/business/matrix/account/openAuthCB${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 校验D音Cookie接口授权状态
export async function qrCookieConnect2 (data) {
  const res = await request.post('/business/douyin/open/auth/qrConnect', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 快手点击作品，返回列表展示
export async function qrCookieConnect(dataInfo) {
  console.log('dataInfo',dataInfo)
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    token:dataInfo.data.token, // 令牌
    s_v_web_id:dataInfo.s_v_web_id, // web_id
    cookie:dataInfo.cookie, // cookie
    // object转string传入
    proxies:JSON.stringify(dataInfo.proxies), // 代理
  };
  let url = `/business/matrix/account/douyin/open/auth/qrConnect${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 校验D音自研接口授权状态
export async function qrConnect (data) {
  const res = await request.post('/business/matrix/account/douyin/qr_connect', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}



// 快手点击作品，返回列表展示
export async function ksPhotoList(token) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    token: token
  };
  let url = `/business/matrixkspublish/photoList${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 抖音点击作品，返回列表展示
export async function dyPhotoList(openId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    openId: openId
  };
  let url = `/business/matrix/dypublish/getVideoList${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}






